home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Informant Complete 1995 - 2000
/
Delphi Informant Complete 1995 to 2000.iso
/
Delphi Informant Magazine Complete Works SOURCE CODE 1998.rar
/
1998
/
Nov
/
di9811gd
/
Example2
/
DllCode.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1998-04-25
|
2KB
|
82 lines
unit DllCode;
interface
uses Windows, Dialogs, SysUtils, Forms;
procedure DllShowMessage(Msg: String);
{ Assume that szResult is at least as long as sz }
procedure GetFirstWord(sz, szResult: PChar); stdcall export;
procedure GetNextWord(sz, szResult: PChar); stdcall export;
const
MessageBoxTitle = 'Dll2';
CRLF = #13 + #10;
implementation
threadvar
gCurrentWordIndex: Integer;
procedure DllShowMessage(Msg: String);
begin
MessageBox(GetDesktopWindow, PChar(Msg), MessageBoxTitle,
MB_OK or MB_SETFOREGROUND or MB_TASKMODAL);
end;
function FindCurrentWord(st: String): String;
var
Len, j: Integer;
begin
j := gCurrentWordIndex; Len := Length(st);
{* Find where the word begins... *}
while (j <= Len) and
(not (st[j] in ['A'..'Z','a'..'z','0'..'9'])) do Inc(j);
gCurrentWordIndex := j;
{* Find where the word ends... *}
while (j <= Len) and
(st[j] in ['A'..'Z','a'..'z','0'..'9']) do Inc(j);
result := Copy(st, gCurrentWordIndex, j - gCurrentWordIndex + 1);
gCurrentWordIndex := j;
end;
procedure GetFirstWord(sz, szResult: PChar);
var
st: String;
begin
gCurrentWordIndex := 1;
StrPCopy(szResult, FindCurrentWord(String(sz)));
end;
procedure GetNextWord(sz, szResult: PChar);
begin
StrPCopy(szResult, FindCurrentWord(String(sz)));
end;
procedure DllEntry(Reason: Integer);
begin
case Reason of
DLL_THREAD_ATTACH: begin
DllShowMessage('Thread attaching. (Thread ID: ' +
IntToStr(GetCurrentThreadID) + ')');
end;
DLL_THREAD_DETACH: begin
DllShowMessage('Thread detaching. (Thread ID: ' +
IntToStr(GetCurrentThreadID) + ')');
end;
end;
end;
initialization
DllShowMessage('Initializing process-level stuff.');
IsMultiThread := True;
DllProc := @DllEntry;
finalization
DllShowMessage('Cleaning up process-level stuff.');
end.